/**
 * @author Ming & Tony
 * Token.java
 * Represent tokens in expressions or equations.
 */

package calculator;

class Token {

    enum TokenType {
        NUL, DOUBLE_TOKEN, OPERATOR_TOKEN
    }
    //final static int DOUBLE_TOKEN   = 1;
    //final static int OPERATOR_TOKEN = 2;

    boolean     hasNext     = false;
    TokenType   type        = TokenType.NUL;
    double      doubleVal   = -1.0; //store the value of the decimal if the token is a decimal
    String      strVal      = "";   //store the value of the operator if the token is an operator

    Token (double value) {
        this.type = TokenType.DOUBLE_TOKEN;
        this.doubleVal = value;
    }

    Token (String value) {
        this.type = TokenType.OPERATOR_TOKEN;
        this.strVal = value;
    }

    double getDoubleValue () {
        return this.doubleVal;
    }

    String getStrValue () {
        return this.strVal;
    }

    boolean hasNext () {
        return hasNext;
    }

    void setHasNext (boolean hasNext) {
        this.hasNext = hasNext;
    }

    TokenType getType () {
        return this.type;
    }

    @Override
    public String toString () {
        if (this.getType() == TokenType.DOUBLE_TOKEN) {
            return this.doubleVal + "";
        } else {
            return this.strVal;
        }
    }
}
